<template>
    <!-- <input type="file" name="file" accept="image/*" @change="handleuploadFile($event)"/> -->
    <!-- <div>
      <button @click="handleSubmit">提交</button>
    </div> -->
    <div class="flex">
      <div class="chat">
        <h2>客户聊天区域</h2>
        <div class="box">
          <div class="lishi">
            <!-- <p>历史记录</p> -->
            <div class="kefu-left">
              <div></div>
            </div>
            <div class="kehu-right">
              <div></div>
            </div>
          </div>
          <div class="chatbox">
            <div id="father">
              <wangeditor :catchData="catchData"></wangeditor>
            </div>
          </div>
        </div>
      </div>
      <!-- <div class="chat">
        <File/>
      </div> -->
      
    </div>
</template>
 
<script>
import wangeditor from './component/wangeditor'
import './chat.scss'
import File from './file'
// import axios from "axios";
import store from '../../store'
import mqtt from 'mqtt'
import {initkehuWs, wsSend} from './kehuchat'
import {initkefuWs, wsSendkefu} from './kefuchat'
import {initKefulist} from './kefulist'
import getters from '../../store/getters'
// customerSerOnline 客服列表

export default {  
  components: {
    File,
    wangeditor
  },
  data() {
    return {
      content: '',
      editors: '',
      diaVisible: true,
      file: '',
      kefuInput: '',
      chatInput: '上传图片'
    };
  },
  mounted () {
    
    initkehuWs()
    wsSend(`chating/history/kf1`, '7')
    // initkefuWs(store.getters.uid, "ws://bj.tjanta.com:8001/mqtt", "customerSerOnline", res => {
    //   console.log(res)
    // })
    // initKefulist()
  },
  methods: {
    catchData(value){
      this.content=value   //在这里接受子组件传过来的参数，赋值给data里的参数
      console.log(this.content)
    },
    dialogClose () {

    },
    // 发送WebSocket请求
    wsSend (parameter) {
      // console.log(parameter)
      parameter = parameter
      client.publish(`chating/customer/${store.getters.uid}`, parameter)
    },
    sendMessage () {},
    handleChat1 () {},
    handleChat2 () {},
    send1 () {
      this.wsSend(this.chatInput, )
    },
    send2 () {},
    handleuploadFile (evt, flg) {
      let files = Array.prototype.slice.call(evt.target.files)
      let vm = this
      files.forEach(function (file, i) {
        
        let reader = new FileReader()
        reader.onload = function (fv) {
          let data = fv.target.result
          console.log(data)
          // let image = data.split(',')[1]
          vm.chatInput = data
          // console.log('base64', image)
        }
        reader.readAsDataURL(file)
      })
    }
  }
}

</script>